
import dayjs from "dayjs";
import rt from 'dayjs/plugin/relativeTime'
import Vue from "vue";

//格式化后台返回的时间戳
const dataFilter = (time,format = 'YYYY-MM-DD') =>{
    if(!isNaN(time)) {
        time = parseInt(time)
    }
    return dayjs(time).format(format)
}

//加载相对时间插件
dayjs.extend(rt)
const relativeTime = (time) => {
    if(!isNaN(time)){
        time = parseInt(time)
    }
    return dayjs().to(dayjs(time))
}

//格式化后台返回的时间戳
Vue.filter("dataFilter",dataFilter)

//处理相对时间
Vue.filter("relativeTime",relativeTime)




export default {
    dataFilter,
    relativeTime
}